package com.ktjy.util.Interceptor;

import com.ktjy.pojo.SysUser;
import com.ktjy.util.Constants;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.servlet.HandlerInterceptor;

public class AuthInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("进入自定义拦截器");
        String servletPath = request.getServletPath();
        HttpSession session = request.getSession();
        Object sysUser = session.getAttribute(Constants.SESSION_USER);
        if (sysUser == null) {
            response.sendRedirect("/ch15/error.jsp");
            return false;
        } else {
            return true;
        }
        //return HandlerInterceptor.super.preHandle(request, response, handler);
    }
}
